<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>首页展示</title>
</head>
<body>
<div>
    <h3>欢迎使用员工管理系统【员工姓名:${employee.name}】
        【部门:${employee.department.name}】
        【岗位:${employee.positions.nameCn}】</h3>
</div>
<table width="1000px">
    <caption>
        <form action="queryEmp" method="post">
            <label>员工姓名:</label>
            <input type="text" name="name" value="${param.name}"/>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <label>所属部门:</label>
            <select name="depteid">
                <option value="-1">请选择部门</option>
                <c:forEach items="${depts}" var="dept">
                    <c:if test="${dept.depteid == param.depteid}">
                        <option value="${dept.depteid}" selected>${dept.name}</option>
                    </c:if>
                    <c:if test="${dept.depteid != param.depteid}">
                        <option value="${dept.depteid}">${dept.name}</option>
                    </c:if>
                </c:forEach>
            </select>

            <input type="submit" value="查询"/>
        </form>
    </caption>
    <thead>
    <tr>
        <th>员工编号</th>
        <th>员工姓名</th>
        <th>所属部门</th>
        <th>职务</th>
        <th>状态</th>
        <th>头像</th>
        <th>邮箱</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pageInfo.list}" var="emp">
        <tr>
            <td>${emp.empid}</td>
            <td>${emp.name}</td>
            <td>${emp.department.name}</td>
            <td>${emp.positions.nameCn}</td>
            <td>${emp.status}</td>
            <td><img src="/img/${emp.img}" width="100px" height="50px"></td>
            <td>${emp.email}</td>
            <td>操作</td>
        </tr>
    </c:forEach>
    </tbody>
    <tfoot>
    <tr>
        <td colspan="6">
            <input type="hidden" name="pageNo" value="${pageInfo.currPageNo}"/>||
            <input type="hidden" name="pages" value="${pageInfo.totalPages}"/>
            <select name="pageSize">
                <c:if test="${empty param.pageSize}">
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                </c:if>
                <c:if test="${param.pageSize == 2}">
                    <option value="2" selected>2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                </c:if>
                <c:if test="${param.pageSize == 3}">
                    <option value="2">2</option>
                    <option value="3" selected>3</option>
                    <option value="4">4</option>
                </c:if>
                <c:if test="${param.pageSize == 4}">
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4" selected>4</option>
                </c:if>
            </select>
            <a href="addEmp.jsp">添加员工信息</a>
            &nbsp;&nbsp;
            <a href="javascript:void(0)" class="first">首页</a>
            <a href="javascript:void(0)" class="up">上一页</a>
            <a href="javascript:void(0)" class="next">下一页</a>
            <a href="javascript:void(0)" class="last">末页</a>
            |共${pageInfo.totalPages}|条数${pageInfo.totals}
        </td>
    </tr>
    </tfoot>
</table>
<script type="text/javascript" src="/js/jquery3.6.4.js"></script>
<script type="text/javascript">
    $(function () {
        $(".first").click(() => {
            jump(1)
        });
        $(".up").click(() => {
            let pageNo = $("input[name=pageNo]").val();
            pageNo = parseInt(pageNo) - 1;
            jump(pageNo)
        });
        $(".next").click(() => {
            let pageNo = $("input[name=pageNo]").val();
            pageNo = parseInt(pageNo) + 1;
            jump(pageNo)
        });
        $(".last").click(() => {
            let pageNo = $("input[name=pages]").val();
            jump(pageNo)
        });
    })

    function jump(pageNo) {
        let pageSize = $("select[name=pageSize]").val();
        let name = $("input[name=name]").val();
        let depteid = $("select[name=depteid]").val();
        let url = '/queryEmp?pageNo=' + pageNo + '&pageSize=' + pageSize + '&name=' + name + '&depteid=' + depteid;
        console.log(url);
        location.href = url;
    }
</script>
</body>
</html>
